#include "clientbase.h"
#include "Poco/Net/SocketReactor.h"
#include "ByteBufferPool.h"
#include "Poco/Util/Application.h"

using namespace cm_xmpp;
using namespace cm_nat;
using namespace Poco;
using namespace Poco::Net;
using namespace Poco::Util;

int main()
{
    Application* p_app = new Application;
    p_app->loadConfiguration("c:/test/test_case.xml");


    SocketReactor reactor;
    reactor.setTimeout(Poco::Timespan(1,0,0,0,0));

    ByteBufferPool bpool;
    bpool.setup(10, 1024);

    ClientBase cb(&bpool);
    cb.init();

    TcpPort tp(reactor, &bpool);
    tp.setHandler(&cb);

    cb.setPort( &tp );

    SocketAddress sa("jabber.org","5222");
    tp.init(sa);

    std::string head = "<?xml version='1.0' ?>";

    head += "<stream:stream to='jabber.org' xmlns='jabber:client' ";

    head += "xmlns:stream= 'http://etherx.jabber.org/streams'  xml:lang='en' ";

    head += "version='1.0'>";

    ByteBuffer* p_buff = bpool.get(0);
    p_buff->increaseRef();

    p_buff->WriteString( head );


    tp.send( p_buff );

    reactor.run();
    return 0;
}